/*
	Copyright (C) 2009 jungil Han <jungil.Han@gmail.com>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __MKHOTKEYBUTTON_H__
#define __MKHOTKEYBUTTON_H__

#include "../Base/Button/mkButton.h"
#include "../Manager/mkHotkeyManager.h"
#include "../Menu/mkPopupMenu.h"

class mkHttpDownloader;

class mkHotkeyButton : public mkButton {
	Q_OBJECT
	
public:
    mkHotkeyButton( IN QWidget *a_pParent, IN int a_nIndex );
    virtual ~mkHotkeyButton();
	
	int GetIndex();
	
	QString GetName();
	QString GetFilePath();
	
	int LoadHotkey( IN mkHotkeyInfo *a_pHotkeyInfo );
	int GetHotkeyCode( OUT int *a_pSystemKey, OUT int *a_pNonSystemKey );
	int RegisterHotkey( IN int a_nSystemKey, IN int a_nNonSystemKey );

	int EnableIcon( IN bool a_bIsEnable = true );

	void OnDownloadedFavicon( IN QString &a_refFaviconFile, IN QString &a_refTitle, IN QString &a_refUrl );

protected:
	QPixmap GetIcon( IN QString a_strFile );
	QString GetIconName( IN QString a_strFile );

	void SetName( IN QString a_strName );
	void SetFilePath( IN QString a_strFilePath );

	void CompositeFavicon( IN QPixmap &a_refTarget, IN QString &a_refFaviconFile );

	virtual void mousePressEvent( IN QMouseEvent *a_pEvent );
	virtual void dragEnterEvent( IN QDragEnterEvent *a_pEvent );
	virtual void dragLeaveEvent( IN QDragLeaveEvent *a_pEvent );
	virtual void dropEvent( IN QDropEvent *a_pEvent );
	
	virtual void OnPaint( QPainter *a_pPainter );
	virtual void OnEnter( QEvent *a_pPainter );
	virtual void OnLeave( QEvent *a_pPainter );

public slots:
	void SlotFileOpenClicked();
	void SlotURLClicked();
	void SlotConfigClicked();
	void SlotDeleteClicked();

protected slots:
	void SlotClicked();
	void SlotEnterTimer();

signals:
    void SigShowKeyboard( int a_nHotkeyButtonID );
	
private:
	int m_nIndex;
	int m_nSystemKey;
	int m_nNonSystemKey;

	QString m_strName;
	QString m_strFilePath;
	QString m_strKeyInfo;

	mkButton *m_pDeleteButton;
	mkButton *m_pConfigButton;

	QIcon m_hotkeyIcon;

	mkPopupMenu *m_pPopupMenu;
	mkHttpDownloader *m_pHttpFavicon;

	QTimer *m_pEnterTimer;
};

#endif /* __MKHOTKEYBUTTON_H__ */

